<template>
	<el-dialog v-model="showModal" :close-on-click-modal="false" class="peak-dialog" title="执行一次" :width="600">
		<el-form ref="paramsFormRef" class="params-form" :inline="true" label-position="right" label-width="80px" :model="paramsForm">
			<el-row :gutter="16" justify="start">
				<el-col :span="24">
					<el-form-item class="form-item" label="任务参数:" prop="executorParam">
						<el-input v-model="paramsForm.executorParam" rows="3" type="textarea" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item class="form-item" label="机器地址:" prop="addressList">
						<el-input v-model="paramsForm.addressList" rows="3" type="textarea" />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="handleCancel">取 消</el-button>
				<el-button type="primary" @click="handleSureOk">确 定</el-button>
			</span>
		</template>
	</el-dialog>
</template>
<script setup>
import global from '@/utils/global'

/*
 *@Description: 状态初始化
 *@MethodAuthor: liuYuFeng
 *@Date: 2023-09-11 18:32:56
 */

const emit = defineEmits(['peak-modal-ok'])
const state = reactive({
	showModal: false,
	paramsFormRef: null,
	paramsForm: {
		id: '',
		addressList: '',
		executorParam: '',
	},
})

const { showModal, paramsFormRef, paramsForm } = toRefs(state)

/*
 *@Description: 方法模块
 *@MethodAuthor: liuYuFeng
 *@Date: 2023-09-11 18:35:47
 */
const handleSureOk = () => {
	global.$fetchPostData('/meta-system/web/v1/job/trigger', state.paramsForm).then(data => {
		if (data.code == 200) {
			state.showModal = false
			global.$baseMessage('执行成功！', 'success')
			emit('peak-modal-ok', 2)
		} else {
			global.$baseMessage(data.msg, 'error')
		}
	})
}
const handleCancel = () => {
	state.showModal = false
}
const handleShowModal = async row => {
	state.showModal = true
	await nextTick()
	state.paramsFormRef.resetFields()
	state.paramsForm.id = row.id
	state.paramsForm.executorParam = row.executorParam
}

defineExpose({
	handleShowModal,
})
</script>
<style lang="scss" scoped></style>
